﻿using FastExecutor.Base.Design;
using FastIOC.Annotation;
using FastIOC.Builder;
using FastIOC.Desgin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace FastExecutor.Base.Util
{
    public class InjectUtil
    {
        public static ContainerBuilder Container;
        public static void Init()
        {
            InjectFrameWork();
            InjectProject();
        }

        public static void InjectFrameWork()
        {
            Container = new ContainerBuilder();
            //获框架取所有程序集
            var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray();
            //注入框架所有Component组件
            Container.RegisterAssemblyTypes(assemblies, typeof(Component), true);
            Container.Build(CotainerEnum.BuidlModel.OverWrite);
        }

        public static void InjectProject()
        {
            //获取项目所有程序集
            var assemblies = PluginUtil.GetProjectAssemblies().ToArray();
            //注入项目所有Component组件
            Container.RegisterAssemblyTypes(assemblies, typeof(Component), true);
            Container.Build(CotainerEnum.BuidlModel.OverWrite);
        }
    }
}
